<?php
/**
 * Way to hide links to disallowed resources
 * Check whether the authenticated user is allowed access to resources simply by 
 * passing the resource pattern to the allowed() method
 * 
 * @param string $route
 * @return boolean
 */
if (!function_exists('allowed'))
{
    function allowed($route) {
    	foreach (Auth::user()->groups as $group) {
    		foreach ($group->resources as $resource) {
    			if ($resource->pattern == $route) {
    				return true;
    			}
    		}
    	}

        return false;
    }
}

/**
 * Dipslay head column for ajax sort
 * 
 * @param array $options
 * @return string html
 */
if (!function_exists('headColumn'))
{	
	function headColumnSort($options) {		
		$sort = Input::get('sort');
		$order = Input::get('order');
		
		$url = URL::route(Route::currentRouteName()) . "?sort={$options['sort']}&order=";

		$html = $options['label'];
		
		if ($sort == $options['sort']) {
			if ('asc' == $order) {
				return $html .= '
				<a id="sort-desc" href="' . $url . 'desc">
				   	<span class="glyphicon glyphicon-arrow-down"></span>
				</a>';
			} else if ('desc' == $order) {
				return $html .= '
				<a id="sort-asc" href="' . $url . 'asc">
				   	<span class="glyphicon glyphicon-arrow-up"></span>
				</a>';
			}
		}
			
		return $html .= '
			<a id="sort-asc" href="' . $url . 'asc">
			   	<span class="glyphicon glyphicon-arrow-up"></span>
			</a>
			<a id="sort-desc" href="' . $url . 'desc">
			   	<span class="glyphicon glyphicon-arrow-down"></span>
			</a>';
	}
}





